﻿Public Class Character
    Inherits DoubleRectangle
    Implements IDisposable

    Public bufferedImage As Bitmap

    Private fallingSpeed As Int32 = 1

    Public Sub New(loc As Point, sz As Size, sprite As Bitmap)
        MyBase.New(loc, sz)
        Me.bufferedImage = sprite
        Init()
    End Sub

    Public Sub Init()
        'bufferedImage = New Bitmap(Tile.TileSize, Tile.TileSize * 2)
        'Dim gfx As Graphics = Graphics.FromImage(bufferedImage)

        'gfx.DrawImage(Tile.TileSet_Ground, 0, 0, New Rectangle(Id(0) * Tile.TileSize, Id(1) * Tile.TileSize, Tile.TileSize, Tile.TileSize * 2), GraphicsUnit.Pixel)
        'gfx.Dispose()
    End Sub

    Public Sub Tick()
        Dim altitude As Int32 = Y + 2
        Dim underblock As Block = World.world(X, altitude)
        If (underblock.ID = Tile.TileID.Air) Then
            Y += fallingSpeed
        End If
    End Sub

    Public Sub Render(g As Graphics)
        g.DrawImage(bufferedImage, New Point(Me.X * Tile.TileSize, Me.Y * Tile.TileSize))
    End Sub

#Region "IDisposable Support"
    Private disposedValue As Boolean ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                If (Not IsNothing(bufferedImage)) Then
                    bufferedImage.Dispose()
                    bufferedImage = Nothing
                End If
            End If

            ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
            ' TODO: set large fields to null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
    Protected Overrides Sub Finalize()
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(False)
        MyBase.Finalize()
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
